package com.project.platform.exception;

import com.project.platform.vo.ResponseVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;


/**
 * 全局异常拦截
 */
@ControllerAdvice
@Slf4j
public class GlobalExceptionHandler {
    @ExceptionHandler(value = CustomException.class)
    @ResponseBody
    public ResponseEntity<ResponseVO<Object>> CustomExceptionHandler(CustomException e) {
        // 始终返回200，由ResponseVO中的code表达业务失败（409），并把具体原因写入msg
        return new ResponseEntity<>(ResponseVO.fail(409, e.getMessage()), org.springframework.http.HttpStatus.OK);
    }
}
